package org.funny.machine32.base;

public enum RegisterEnum {
    ZERO("$zero", 0),
    AT("$at", 1),
    V0("$v0", 2),
    V1("$v1", 3),
    A0("$a0", 4),
    A1("$a1", 5),
    A2("$a2", 6),
    A3("$a3", 7),
    T0("$t0", 8),
    T1("$t1", 9),
    T2("$t2", 10),
    T3("$t3", 11),
    T4("$t4", 12),
    T5("$t5", 13),
    T6("$t6", 14),
    T7("$t7", 15),
    S0("$s0", 16),
    S1("$s1", 17),
    S2("$s2", 18),
    S3("$s3", 19),
    S4("$s4", 20),
    S5("$s5", 21),
    S6("$s6", 22),
    S7("$s7", 23),
    T8("$t8", 24),
    T9("$t9", 25),
    K0("$k0", 26),
    K1("$k1", 27),
    GP("$gp", 28),
    SP("$sp", 29),
    FP("$fp", 30),
    RA("$ra", 31),
    PC("pc", 32),
    HI("hi", 33),
    LO("lo", 34),
    F0("$f0", 0),
    F1("$f1", 1),
    F2("$f2", 2),
    F3("$f3", 3),
    F4("$f4", 4),
    F5("$f5", 5),
    F6("$f6", 6),
    F7("$f7", 7),
    F8("$f8", 8),
    F9("$f9", 9),
    F10("$f10", 10),
    F11("$f11", 11),
    F12("$f12", 12),
    F13("$f13", 13),
    F14("$f14", 14),
    F15("$f15", 15),
    F16("$f16", 16),
    F17("$f17", 17),
    F18("$f18", 18),
    F19("$f19", 19),
    F20("$f20", 20),
    F21("$f21", 21),
    F22("$f22", 22),
    F23("$f23", 23),
    F24("$f24", 24),
    F25("$f25", 25),
    F26("$f26", 26),
    F27("$f27", 27),
    F28("$f28", 28),
    F29("$f29", 29),
    F30("$f30", 30),
    F31("$f31", 31),
    CF("cf", 32),
    VADDR("$8 (vaddr)", 8),
    STATUS("$12 (status)", 12),
    CAUSE("$13 (cause)", 13),
    EPC("$14 (epc)", 14);

    private String name;
    private int index;

    RegisterEnum(String name, int index) {
        this.name = name;
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return index;
    }

    public static RegisterEnum getRegister(String name) {
        for (RegisterEnum register : values()) {
            if (register.getName().equals(name)) {
                return register;
            }
        }
        return null;
    }
}
